<?php
/**
 * 
 * 页面ajax操作返回
 * @author xun
 *
 */
namespace Home\Controller;
class AjaxController extends BaseController {
	private $Func;
	private $Http;
	private $api_url;
    public function __construct()
    {
        parent::__construct();
        $this->Http = new \Home\Model\HttpModel();
        $this->Func = new \Home\Model\FuncModel();
        $this->api_url = 'http://api.bangbanggou.com/v1/';
    }
    
    /**
     * 收藏操作
     */
    public function collect()
    {
    	echo 1;exit;
    	$params = array();
    	$params['type']   = I('post.type', '', 'int');
    	$params['app_id'] = I('post.app_id', '', 'int');
    	$params['tid']    = I('post.tid', '', 'int');
    	$params['uid']    = I('post.uid', '', 'int');
    	$result = $this->Http->post($this->api_url . 'like', $params);
    	if($result['status'] == 1)
    	{
    		$this->Func->ajaxSucc($result);
    	}
    	$this->Func->ajaxFail($result);
    }
    
    /**
     * 点赞操作
     */
    public function praise()
    {
    	
    	$params = array();
    	$params['type']   = I('post.type', '', 'int');
    	$params['app_id'] = I('post.app_id', '', 'int');
    	$params['tid']    = I('post.tid', '', 'int');
    	$params['uid']    = I('post.uid', '', 'int');
    	$result = $this->Http->post($this->api_url . 'laud', $params);
    	if($result['status'] == 1)
    	{
    		$this->Func->ajaxSucc($result);
    	}
    	$this->Func->ajaxFail($result);
    }
    
    

    /**
     * 加载列表操作
     */
    public function loadlist()
    {
    	echo '{
    "rows": [
        {
            "tid": "3533",
            "sid": "349257",
            "uid": "387016",
            "type": "2",
            "title": "我想买台可以p图的电脑，大概五千左右",
            "content": "美工用的，整体性能稳定，分辩率高些。<img src=\"http://stc.weimob.com/img/sns/emotion/4.gif\" data-innerhtml=\"/:8-)\"></img>",
            "image_url": [
                ""
            ],
            "ctime": "1414331298",
            "utime": "1414331298",
            "status": "0",
            "top": "0",
            "comment": "3",
            "praise": "2",
            "collect": "1",
            "flag": "0",
            "hot": "3",
            "iscollect": "1",
            "ispraise": "1",
            "ruid": 387016,
            "nickname": null,
            "head_img": "http://img.weimob.com/"
        },
        {
            "tid": "3634",
            "sid": "349257",
            "uid": "387016",
            "type": "2",
            "title": "ccc",
            "content": "dddd",
            "image_url": [
                ""
            ],
            "ctime": "1415182119",
            "utime": "1415182119",
            "status": "0",
            "top": "0",
            "comment": "0",
            "praise": "0",
            "collect": "0",
            "flag": "0",
            "hot": "0",
            "iscollect": "0",
            "ispraise": "0",
            "ruid": 387016,
            "nickname": null,
            "head_img": "http://img.weimob.com/"
        }
    ],
    "total": 4,
    "page": 1,
    "size": 15,
    "userinfo": [],
    "shopinfo": {
        "id": "9888",
        "sid": "349257",
        "name": "帮帮购",
        "image": "http://img.weimob.com/static/8a/c4/b6/image/20141026/20141026211304_80638.jpg",
        "nickname": "帮仔",
        "exa_restrict": "0",
        "exa_trends": "0",
        "exa_praise": "0",
        "auto_order": "1",
        "auto_order_num": "3",
        "ctime": "1414329231",
        "utime": "1414331251",
        "flag": "0",
        "top_background": "0",
        "style": ""
    }
}';
    	exit;
    	$params = array();
    	$params['page']   = I('post.page', '', 'int');
    	$params['app_id'] = I('post.app_id', '', 'int');
    	$params['uid']    = I('post.uid', '', 'int');
    	$result = $this->Http->post($this->api_url . 'laud', $params);
    	if($result['status'] == 1)
    	{
    		$this->Func->ajaxSucc($result);
    	}
    	$this->Func->ajaxFail($result);
    	
    }
    

    /**
     * 加载评论内容操作
     *
     */
    public function ajaxComments(){
    	$params = array();
    	$params['app_id'] = I('post.app_id', '', 'int');
    	$params['tid']    = I('post.tid', '', 'int');
    	$params['uid']    = I('post.uid', '', 'int');
    	$params['page']    = I('post.page', '', 'int');
    	//帖子内容页
    	$result = $this->Http->post($this->api_url . 'commentlist', $params);
    	$result = '<li>
	                    <dl class="tbox">
	                        <dd>
	                            <span class="head_img">
	                               <img src="{$vo.user_info.user_pic}" onerror="this.src='{$default_info.default_head}';">
	                            </span>
	                        </dd>
	                        <dd>
	                            <h7>{$vo.user_info.nick}</h7>
	                            <p>{$vo.content}<span class="icons icons_del" onclick="delComment(this, {$site_info.app_id}, {$post_data.id}, {$vo.comment_id}, {$vo.user_info.user_id}, {$vo.user_info.user_id});">&nbsp;</span></p>
	                            <time>
	                                {$vo.comment_time|date="Y-m-d H:i:s",###}
	                                <span>赞 <label id="praise_{$vo.comment_id}">{$vo.laud_count|default=0}</label></span>
	                            </time>
	                        </dd>
	                        <dd>
	                            <span class="icons icons_op" onclick="showOperate(true, this, event);">
	                                <a href="{$site_info.route_base}/index/commentview/comment_id/{$vo.comment_id}" class="btn">回复</a>
	                                <a href="javascript:commentPraise({$vo.is_laud},{$site_info.app_id},{$post_data.id},{$vo.comment_id},{$user_info.user_id});" class="btn" id="cid_{$vo.comment_id}">赞</a>
	                                <a href="javascript:showOperate(false);" class="btn calcel">取消</a>
	                            </span>
	                        </dd>
	                    </dl>
	                </li>';
    
    	if($result['status'] == 1)
    	{
    		$this->Func->ajaxSucc($result);
    	}
    	$this->Func->ajaxFail($result);
    
    }

    /**
     * 加载帖子列表操作
     *
     */
    public function ajaxTrendsList(){
    	$params = array();
    	$params['app_id'] = I('post.app_id', '', 'int');
    	$params['uid']    = I('post.uid', '', 'int');
    	$params['nickName']   = I('post.nickName', '', '');
    	
    	//帖子内容页
    	$result = $this->Http->post($this->api_url . 'editnick', $params);
    
    	if($result['status'] == 1)
    	{
    		$this->Func->ajaxSucc(0);
    	}
    	$this->Func->ajaxFail(1);
    
    } 

    /**
     * 删除帖子操作
     *
     */
    public function deleteTrends(){
    	$params = array();
    	$params['app_id'] = I('post.app_id', '', 'int');
    	$params['tid']    = I('post.tid', '', 'int');
    	$params['uid']    = I('post.uid', '', 'int');
    	$params['page']    = I('post.page', '', 'int');
    	//帖子内容页
    	$result = $this->Http->post($this->api_url . 'commentlist', $params);
    
    	if($result['status'] == 1)
    	{
    		$this->Func->ajaxSucc(0);
    	}
    	$this->Func->ajaxFail(1);
    
    } 

    /**
     * 修改用户昵称操作
     *
     */
    public function ajaxEditNickName(){
    	$params = array();
    	$params['app_id'] = I('post.app_id', '', 'int');
    	$params['uid']    = I('post.uid', '', 'int');
    	$params['nickName']   = I('post.nickName', '', '');
    	
    	//帖子内容页
    	$result = $this->Http->post($this->api_url . 'editnick', $params);
    
    	if($result['status'] == 1)
    	{
    		$this->Func->ajaxSucc(0);
    	}
    	$this->Func->ajaxFail(1);
    
    } 
}